let id=0
class Dep{
    constructor(){
        this.id=id++// dep收集watcher
        this.subs=[]// 存放当前属性对应的watcher有哪些
    }
    depend(){
        // 
        Dep.target.addDep(this)//让watcher记住dep
    }
    addSub(watcher){
        this.subs.push(watcher)
    }
    // 对dep上的watcher通知更新
    notify(){
        this.subs.forEach(watcher=>watcher.update())
    }
}
Dep.target=null
let stack=[]
export function pushTarget(watcher) {
    stack.push(watcher)
    Dep.target=watcher
    // console.log(Dep.target)
}
export function popTarget() {
    stack.pop()
    Dep.target=stack[stack.length-1]
    // console.log(Dep.target)

}

export default Dep